Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable OAuth2 per View #148

Merged
merged 2 commits into from
Nov 26, 2024
Merged

feat: enable OAuth2 per View #148

merged 2 commits into from
Nov 26, 2024

Conversation

shadinaif
Copy link
Collaborator

@shadinaif shadinaif commented Nov 19, 2024

  • feat: custom roles and view-user mapping:
    • Two new roles added that will be used to control the access of OAuth2 users to all views (APIs) of futurex_openedx_extensions:
      • fx_api_access_role_global: acts as a global role. It grants access to all tenants for the permitted view
      • fx_api_access_role: acts as a tenant-wide or course-specific role. It grants limited access to the permitted view
    • Use the new django-admin form to control access to views for OAuth2 users /admin/fx_helpers/viewusermapping/
      • the form shows related information + usable flag that tells the admin if the record permits the related user to access the view or not
  • feat: allow oauth2 on all views: add BearerAuthentication to authentication_classes for all views of the extenstion. This will automatically allow OAuth2 to all views, but the extension will use the View-User-Mapping as an extra security layer to control the access per tenant or course
    • The user must be already given access using OAuth2. For example, to give a third-part-service an OAuth2 access, create an Application in django-oauth2-provider form /admin/oauth2_provider/application/ (Authorization grant type: Confidential, Authorization grant type: Client Credentials)

Sample screenshot of the admin page:
Screenshot from 2024-11-21 10-59-17

@shadinaif shadinaif force-pushed the shadinaif/fx-apis-oauth2 branch 2 times, most recently from 7159f08 to 6629310 Compare November 19, 2024 10:42
Base automatically changed from shadinaif/fix-global-roles-do-not-have-access to main November 19, 2024 10:49
@shadinaif shadinaif force-pushed the shadinaif/fx-apis-oauth2 branch 7 times, most recently from aba799e to d3d4671 Compare November 21, 2024 07:37
:param cls: The class to register
:type cls: Any
"""
def _hacky_update_django_admin_choices(choices: list[tuple[str, str]]) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do it like this because CourseAccessRoleForm class of edx-platform is always declared before our extension

@@ -34,6 +38,123 @@ class Meta:
unique_together = ('view_name', 'allowed_role')


class ViewUserMappingManager(models.Manager): # pylint: disable=too-few-public-methods
Copy link
Collaborator Author

@shadinaif shadinaif Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewUserMappingManager is needed to allow smooth UX in django-admin when sorting and filtering on column values

@shadinaif shadinaif marked this pull request as ready for review November 21, 2024 07:45
@shadinaif shadinaif force-pushed the shadinaif/fx-apis-oauth2 branch from d3d4671 to e43d45f Compare November 24, 2024 05:56
@OmarIthawi
Copy link
Collaborator

Thanks @shadinaif, let's discuss it tomorrow in our 1-1

Copy link
Collaborator

@tehreem-sadat tehreem-sadat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, also did quick testing on stage.

Copy link
Collaborator

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

çok güzel! okudum anladım kabul ettim :)

futurex_openedx_extensions/dashboard/views.py Outdated Show resolved Hide resolved
futurex_openedx_extensions/helpers/admin.py Outdated Show resolved Hide resolved
@shadinaif shadinaif force-pushed the shadinaif/fx-apis-oauth2 branch from e43d45f to 903da3f Compare November 26, 2024 05:24
@shadinaif shadinaif merged commit e4e3a89 into main Nov 26, 2024
3 checks passed
@shadinaif shadinaif deleted the shadinaif/fx-apis-oauth2 branch November 26, 2024 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants